package thread;

import static java.lang.Thread.sleep;

//使用lambda 表达式
public class ThreadDemo9 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello thread");
                try {
                    sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
            System.out.println("线程执行结束");
        });
        t.start();
        sleep(2000);
        t.interrupt();
    }
}
